"""
Restful API 模块：用户信息
"""

from flask import (jsonify, request)

from app.web import manage
from app.web.controller import token_required
from app.apiservice.userinfo import UserInfoApiService


@manage.route('/api/user/login', methods=['POST'])
def user_login():
    name = request.values.get('name', None)
    password = request.values.get('password', None)

    result = UserInfoApiService.login(name=name, password=password)
    return jsonify(result)


@manage.route('/api/user/logout', methods=['POST'])
@token_required
def user_logout():
    token = request.values.get('token', None)
    result = UserInfoApiService.logout(token=token)
    return jsonify(result)
